package com.android.kotlincoroutinemvvmdemo.dialog

import android.content.Context
import android.graphics.Bitmap
import android.os.Bundle
import com.android.kotlincoroutinemvvmdemo.R
import com.android.kotlincoroutinemvvmdemo.databinding.DialogBlurEffectBinding

class BlurEffectDialog(context: Context, bmp: Bitmap?) :
    BaseDialog2<DialogBlurEffectBinding>(context, R.style.DefineDialogStyle_COLOR_CC000000) {

    private val mBmp = bmp

    override fun getLayoutId() = R.layout.dialog_blur_effect

    override fun getColorValue() = R.color.color_00000000

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)

        setBgBmp(mBmp)

        mBinding.clBlurEffect.setOnClickListener {
            if (isShowing) {
                dismiss()
            }
        }

        //判断activity是否销毁来决定显示dialog
         /*
         * Context context = ((ContextWrapper) getContext()).getBaseContext();
         * if (context instanceof Activity activity) {
              if (!activity.isFinishing() && !activity.isDestroyed()) {
                   dialog.show();
               }
            }
         * */
    }

    fun setBgBmp(bmp: Bitmap?) {
        if (bmp != null) {
            mBinding.ivBlurView.setImageBitmap(bmp)
        }
    }
}